#!/bin/bash
# - benchmark

# We'll use the below global env vars, but not treat them as parameters to avoid
# duplicates in result path like /openeuler-20.03-aarch64/openeuler-aarch64-cifs-2003/
# os
# os_arch
# os_version
# os_mount
# mount_repo_name
# mount_repo_addr

. $LKP_SRC/lib/rpm.sh
. $LKP_SRC/lib/debug.sh
. $LKP_SRC/lib/misc-base.sh

[ -n "$benchmark" ]	|| die "benchmark is empty"
[ -n "$os_mount" ]	|| die "os_mount is empty"
[ -n "$os" ]		|| die "os is empty"
[ -n "$os_arch" ]	|| die "os_arch is empty"
[ -n "$os_version" ]	|| die "os_version is empty"

DEPS_MNT=/initrd/deps	&& mkdir -p "$DEPS_MNT"
DISTRO=${os}

[[ "$os_mount" = "cifs" ]] && os_mount="nfs"
pack_to=${DEPS_MNT}/${os_mount}/${os}/${os_arch}/${os_version}/${benchmark}

pack_arch=$os_arch
[[ "$benchmark" = "${benchmark##*.}" ]] ||
{
        pack_arch="${benchmark##*.}"
}

. $LKP_SRC/distro/common
load_distro_funcs $DISTRO

umask 002

[[ -d "$pack_to" ]] || {
	mkdir -p "$pack_to"
	chown .lkp "$pack_to"
}

add_repo

share_debian_package

fixup_distro_mirror

update

fixup_preinstall

fixup_arch_install $pack_arch

pack_benchmark_deps

rename_cgz_file

upload_to_target_dir ${pack_to}
